import keyboard
import pyautogui
import time
import threading
import pyperclip

def get_mouse_position():
    try:
        x, y = pyautogui.position()
        print(f"当前鼠标位置：({x}, {y})")
        return x, y
    except Exception as e:
        print(f"获取鼠标位置失败: {e}")
        return None, None

def click_mouse(position, click_count=1, interval=1):
    try:
        for i in range(click_count):
            pyautogui.click(x=position[0], y=position[1])
            print(f"已点击 {i + 1} 次")
            time.sleep(interval)
        print("点击结束")
    except Exception as e:
        print(f"点击失败: {e}")


def main():
    pyperclip.copy("内容非常真实，能写出在实习中的点滴体会，非常好")
    print("欢迎使用鼠标自动点击程序！")

    # 获取鼠标位置
    x, y = get_mouse_position()
    #
    # if x is None or y is None:
    #     print("无法获取鼠标位置，程序退出。")
    #     return
    #
    # # 用户输入点击次数和间隔时间
    # try:
    #     click_count = int(input("请输入点击次数："))
    #     interval = float(input("请输入点击间隔时间（秒）："))
    # except ValueError:
    #     print("输入无效，程序退出。")
    #     return

    # 执行鼠标点击
    for i in range(0,20):
        time.sleep(1)
        #click_mouse((967,726), click_count, interval)
        click_mouse((967, 726),1, 0.5)
        keyboard.press_and_release('ctrl + v')
        time.sleep(0.5)
        click_mouse((940, 915),1, 0.5)
        # time.sleep(3)
        click_mouse((1345, 989),1, 0.5)
        if keyboard.is_pressed('esc'):
            break  # 退出循环
if __name__ == "__main__":
    main()